package com.xoa.service.received.impl;


import com.xoa.dao.sms3.Sms3Mapper;
import com.xoa.model.sms3.Sms3;
import com.xoa.service.received.Sms3Service;

import com.xoa.util.ToJson;
import com.xoa.util.page.PageParams;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class Sms3ServiceImpl implements Sms3Service {

    @Resource
    private Sms3Mapper sms3Mapper;


    @Override
    public ToJson<Sms3> selectSms3(HttpServletRequest request, HttpServletResponse response, Integer page, Integer pageSize, boolean useFlag, Sms3 sms3) {

        ToJson<Sms3> json = new ToJson<Sms3>();
        PageParams pageParams = new PageParams();
        pageParams.setPageSize(pageSize);
        pageParams.setPage(page);
        pageParams.setUseFlag(useFlag);


        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("page", pageParams);
            map.put("sms3",sms3);
            List<Sms3> list = sms3Mapper.selectSms3(map);
          /*  SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
            String format = sdf.format(pzFullRelease.getpOutPrisonTime());
            pzFullRelease.setOutTime(format);

            String format1 = sdf.format(pzFullRelease.getpJoinDate());
            pzFullRelease.setJoinDate(format1);*/

            if (list.size() > 0) {
                json.setObj(list);
                json.setTotleNum(pageParams.getTotal());
                json.setMsg("success");
                json.setFlag(0);
            }
        } catch (Exception e) {

            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;

    }

    @Transactional
    public ToJson selectSms3ById(HttpServletRequest request, Integer smsId) {
        ToJson<Sms3> json = new ToJson<Sms3>();
        try {
            Sms3 sms3 = sms3Mapper.selectByPrimaryKey(smsId);
          /*  SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
            String format = sdf.format(pzFullRelease.getpOutPrisonTime());
            pzFullRelease.setOutTime(format);

            String format1 = sdf.format(pzFullRelease.getpJoinDate());
            pzFullRelease.setJoinDate(format1);*/

            json.setObject(sms3);
            json.setFlag(0);
            json.setMsg("ok");
        } catch (Exception e) {

            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }

    @Transactional
    public ToJson insertSms3(Sms3 sms3) {
        ToJson<Sms3> toJson = new ToJson<Sms3>(1, "error");
        try {
            int temp = sms3Mapper.insertSelective(sms3);
            if (temp > 0) {
                toJson.setFlag(0);
                toJson.setMsg("success");
            }
        } catch (Exception e) {
            toJson.setFlag(1);
            toJson.setMsg(e.getMessage());
            e.printStackTrace();
        }

        return toJson;

    }

    @Transactional
    public ToJson delSms3(Sms3 sms3) {
        ToJson toJson = new ToJson(1, "error");
        try {
            int temp = sms3Mapper.delSms3(sms3);
            if (temp > 0) {
                toJson.setFlag(0);
                toJson.setMsg("success");
            }
        } catch (Exception e) {
            toJson.setFlag(1);
            toJson.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return toJson;
    }
    @Transactional
    public ToJson upSms3(Sms3 sms3) {
        ToJson toJson = new ToJson<>(1, "error");
        try {
            int temp = sms3Mapper.updateByPrimaryKeySelective(sms3);
            if (temp > 0) {
                toJson.setFlag(0);
                toJson.setMsg("success");
            }
        } catch (Exception e) {
            toJson.setFlag(1);
            toJson.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return toJson;

    }







}